package com.qiku.service.impl;

import com.qiku.dao.CourseContentMapper;
import com.qiku.domain.Course;
import com.qiku.domain.CourseLesson;
import com.qiku.domain.CourseSection;
import com.qiku.service.CourseContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CourseContentServiceImpl implements CourseContentService {
    @Autowired
    private CourseContentMapper courseContentMapper;

    /**
     * 根据课程ID查询章节与课时信息
     * @param courseId
     * @return
     */
    @Override
    public List<CourseSection> findSectionAndLessonByCourseId(int courseId) {
        return courseContentMapper.findSectionAndLessonByCourseId(courseId);
    }
    /**
     * 新增章节信息
     * @param section
     * @return
     */
    @Override
    public void saveSection(CourseSection section) {
        //补全信息
        Date date = new Date();
        section.setCreateTime(date);
        section.setUpdateTime(date);
        courseContentMapper.saveSection(section);
    }
    /**
     * 修改章节信息
     * @param section
     * @return
     */
    @Override
    public void updateSection(CourseSection section) {
        //补全信息
        Date date = new Date();
        section.setUpdateTime(date);
        courseContentMapper.updateSection(section);
    }

    /**
     * 修改章节状态
     * @param id
     * @param status
     * @return
     */
    @Override
    public int updateSectionStatus(Integer id , int status) {
        CourseSection section = new CourseSection();
        Date date = new Date();
        section.setUpdateTime(date);
        section.setId(id);
        section.setStatus(status);
        return courseContentMapper.updateSectionStatus(section);
    }

    /**
     * 回显章节对应的课程信息
     * @param courseId
     * @return
     */
    @Override
    public Course findCourseById(int courseId) {
        return courseContentMapper.findCourseById(courseId);
    }

    /**
     * 保存课时信息
     * @param courseLesson
     * @return
     */
    @Override
    public int saveLesson(CourseLesson courseLesson) {
        Date date = new Date();
        courseLesson.setCreateTime(date);
        courseLesson.setUpdateTime(date);
        return courseContentMapper.saveLesson(courseLesson);
    }

}
